package com.leyou.item.web;


import com.github.pagehelper.PageInfo;
import com.leyou.item.pojo.Acl;
import com.leyou.item.pojo.AclModule;
import com.leyou.item.service.AclService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:yanjizhw@163.com
 * @date:2019-10-12 14:28
 * 描述:
 * @since:1.0.0
 */
@Controller
@RequestMapping("acl")
public class AclController {

    @Autowired
    private AclService aclService;

    @RequestMapping("saveAcl")
    public String saveAcl(Acl acl){

        aclService.save(acl);

        return "permission";
    }

    @ResponseBody
    @RequestMapping("queryAcl")
    public ResponseEntity<Map<String, Object>> queryAcl(@RequestParam(value="page", defaultValue = "1") Integer page){

        Map<String, Object> map = new HashMap<>();
        int pageSize = 10; //每页显示条数
        PageInfo<Acl> info =aclService.queryAcl(page, pageSize);

        long totalPage = info.getTotal() / pageSize;

        if (info.getTotal() % pageSize != 0){
            totalPage ++;
        }

        // 封装数据，并返回
        map.put("page", page);
        map.put("pageSize", pageSize);
        map.put("totalPage", totalPage);
        map.put("list", info.getList());

        return ResponseEntity.ok(map);
    }

    @ResponseBody
    @RequestMapping("getSelectAclParent")
    public ResponseEntity<List<Acl>> getSelectAclParent(){

        List<Acl> Lists = aclService.querySelectAclParent();

        return ResponseEntity.ok(Lists);
    }
}
